package com.inspur.cloud.security;

import com.inspur.cloud.entity.dataspace.UserEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.GrantedAuthority;

import java.util.Collection;

public class ApiAuthentication implements Authentication {

    private Collection<? extends GrantedAuthority> authorities;

    private UserEntity user;

    private boolean authenticated;

    public ApiAuthentication(UserEntity user, Collection<? extends GrantedAuthority> authorities, boolean authenticated) {
        this.authorities=authorities;
        this.user = user;
        this.authenticated = authenticated;
    }

    @Override
    public Collection<? extends GrantedAuthority> getAuthorities() {
        return authorities;
    }

    @Override
    public Object getCredentials() {
        return user.getName();
    }

    @Override
    public Object getDetails() {
        return user;
    }

    @Override
    public Object getPrincipal() {
        return user.getPassword();
    }

    @Override
    public boolean isAuthenticated() {
        return authenticated;
    }

    @Override
    public void setAuthenticated(boolean authenticated) throws IllegalArgumentException {
        this.authenticated=authenticated;
    }

    @Override
    public String getName() {
        return user.getName();
    }

    public Integer getId(){
        return user.getId();
    }
}
